// pages/respecting_members/respecting_members.js

var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
var mph = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    get_vip_flag_list: [],
    my_uid: false,
  },
  //临时会员卡
  get_vip_flag_list() {
    let that = this;
    var url = 'index.php?act=vipopen&op=vip_flag_list';
    let k = wx.getStorageSync('key');

    let list = { act: 'vipopen', op: 'vip_flag_list', key: k };
    mph.postRequest(url, list, function (res) {
      // res.data.datas.flag_list/
      console.log('临时会员卡:==?:', res.data.datas, res);
      if (res.data.code == 200) {
        console.log(res.data.datas);
        that.setData({
          get_vip_flag_list: res.data.datas.flag_list
        })
      }
    })
  },
  use_temp_flag_btn() {
    let that = this;
    let k = wx.getStorageSync('key');
    let voucher_id = wx.getStorageSync('voucher_id');
    wx.request({
      url: ApiUrl + '/index.php?act=vipopen&op=use_temp_flag',
      data: {
        key: k,
        flag: voucher_id
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        if (result.statusCode == 200) {

          let res = result.data.datas;
          if (result.data.code == 200) {
            that.setData({
              my_uid: false
            })

            wx.showToast({
              title: res,
              icon: 'success',
              duration: 1000
            })
          } else {
            that.setData({
              my_uid: false
            })

            wx.showToast({
              title: res.error,
              icon: 'success',
              duration: 1000
            })
          }
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_vip_flag_list();

    if (options.voucher_id){
      this.setData({
        my_uid: true
      })
      wx.setStorageSync('voucher_id', options.voucher_id);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

    let voucher_id = this.data.get_vip_flag_list[0];


    return {
      title: '有好友赠送你一张临时会员卡，快来笑纳吧',
      imageUrl: '/image/WechatIMG91.jpeg',//图片地址
      path: '/pages/respecting_members/respecting_members?voucher_id=' + voucher_id ,// 用户点击首先进入的当前页面
      success: function (res) {
        // 转发成功
        console.log("转发成功:");
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:");
      }
    }
  }
})